### Author: Pat Devlin ### 2013-July-02 ## Feel free to use this as you like, but please let me know when you do so (and provide acknowledgement when appropriate). ## Here is a (short) script containing some basic algorithms to compute some ## sequences related to perimeter of integer subsets. ## a18 is to calculate the nth term of Sloane A182372 [the number of non-negative integer subsets with volume n] # a18:=proc(n): return a18_given_max_el(n,n): end proc: ## # This computes the number of subsets having volume n and maximum element AT MOST maxElement a18_given_max_el:=proc(n, maxElement) option remember: ## Begin base cases if((n=0) and (maxElement < 0)) then return 1: fi: if((n=0) and (maxElement >=0)) then return 2: fi: if((n<0)) then return 0: fi: if((n>0) and (maxElement < 1)) then return 0: fi: ## End base cases ## Conditions based on the largest element of {-1, 0, 1, 2, ..., maxElement} NOT in the sets of interest return a18_given_max_el(n, maxElement-1) + a18_given_max_el(n-maxElement, maxElement-2) + add(a18_given_max_el(n-maxElement-(maxElement-k), maxElement-k-2) , k=1..maxElement); end proc: ## a34 is to calculate the nth term of Sloane A227134 [Partitions of n with parts repeated at most twice and repetition only allowed # if first part has an odd index (first index = 1) ] ## a35 is to calculate the nth term of Sloane A227135 [Partitions of n with parts repeated at most twice and repetition only allowed # if first part has an even index (first index = 1) ] a34:=proc(n) return repeats_allowed_on_odd_given_min_part(n,1): end proc: a35:=proc(n) return repeats_allowed_on_even_given_min_part(n,1): end proc: ## This is to calculate number of partitions of n (as above) but with the # minimum part AT LEAST minPart repeats_allowed_on_odd_given_min_part:=proc(n, minPart) option remember: ## Base cases if(n=0) then return 1: fi: # if((n=0) and (minPart <=0)) then return 0: fi: if(n<0) then return 0: fi: if(minPart>n) then return 0: fi: if(n=minPart) then return 1: fi: ## End base cases ## This conditions on whether or not the element minPart is in fact in the partition (and if so, how many times it is) return repeats_allowed_on_odd_given_min_part(n, minPart+1) + repeats_allowed_on_even_given_min_part(n-minPart, minPart+1) + repeats_allowed_on_odd_given_min_part(n-2*minPart, minPart+1): end proc: ## This is to calculate number of partitions of n (as above) but with the # minimum part AT LEAST minPart repeats_allowed_on_even_given_min_part:=proc(n, minPart) option remember: ## Base cases if(n=0) then return 1: fi: # if((n=0) and (minPart <=0)) then return 1: fi: if((n<0)) then return 0: fi: if((minPart>n)) then return 0: fi: if(n=minPart) then return 1: fi: ## End base cases ## This conditions on whether or not the element minPart is in fact in the partition return repeats_allowed_on_even_given_min_part(n, minPart+1) + repeats_allowed_on_odd_given_min_part(n-minPart, minPart+1): end proc: